# coding: utf-8
# from json import load
#
# with open('data.json', 'r', encoding='utf-8') as f:
#     data = load(f)['data']
#     for i, item in enumerate(data):
#         with open(f'data{i}.txt', 'a+', encoding='utf-8') as f:
#             eps = item['source']['eps']
#             for ep in eps:
#                 string = f'{ep["name"]}, {ep["url"]}\n'
#                 f.write(string)


from PyFilesDownloader import AsyncM3U8Downloader

with open('data1.txt', 'r', encoding='utf-8') as f:
    data = f.readlines()
    for line in data[168:]:
        name, url = line.strip().split(', ')
        save_path = 'G:/视频/完美世界'
        file_name = f'{name}.mp4'
        print(f'Downloading {save_path}/{file_name}, {url}...')
        try:
            downloader = AsyncM3U8Downloader(
                url=url,
                save_path=save_path,
                file_name=file_name,
                merge_mode='ffmpeg',
                timeout=10,
            )
            downloader.run()
        except Exception as e:
            print(e)
            continue
